<template>
	<view class="cart-box" v-if="cart.length != 0">
		<my-address></my-address>
		<view class="cart-top">
			<!-- 左侧的图标 -->
			  <uni-icons type="shop" size="18"></uni-icons>
			  <!-- 描述文本 -->
			  <text class="cart-title-text">购物车</text>
		</view>
		<view class="cart-list">
			<uni-swipe-action>
				<view class="cart-item" v-for="(item ,i) in cart" :key="i">
					<uni-swipe-action-item :right-options="options" @click="clickDelete(item)">
						<my-goods 
						:item="item" 
						:bgcolor="white" 
						:showNum="true" 
						:showRadio="true" 
						@radio-change="radioChange"
						@num-change="numberChangeHandler"></my-goods>
					</uni-swipe-action-item>
				</view>
			</uni-swipe-action>
		</view>
		<my-settle></my-settle>
	</view>
	<view class="cart-empty" v-else>
		<image src="/static/cart_empty@2x.png" class="cart-empty-image"></image>
		<text class="tip-text">空空如也~</text>
	</view>
</template>

<script>
	import tabbar from '@/mixins/tabbar-badge.js'
	import { mapState,mapMutations } from 'vuex'
	export default {
		mixins: [tabbar],
		computed: {
			...mapState('m_cart',['cart'])
		},
		data() {
			return {
				 options:[
					{
						text: '删除',
						style: {
							backgroundColor: 'red'
						}
					}
				  ]
			}
		},
		methods: {
			...mapMutations('m_cart',['updateGoodsState','updateGoodsNum','deleteGoods']),
			//修改购物车勾选
			radioChange(ref){
				this.updateGoodsState(ref)
			},
			//修改购物车数量
			numberChangeHandler(ref){
				this.updateGoodsNum(ref)
			},
			//购物车删除按钮
			clickDelete(item){
				this.deleteGoods(item.goods_id)
			}
		}
	}
</script>

<style lang="scss">
.cart-top{
	background-color: white;
	height: 40px;
	align-items: center;
	display: flex;
	padding-left: 5px;
	border-bottom: 1px solid #efefef;
	.cart-title-text{
		font-size: 12px;
		margin-left: 10px;
	}
}
.cart-box{
	margin-bottom: 50px;
}
.cart-empty{
	align-items: center;
	display: flex;
	flex-direction: column;
	// justify-content: space-between;
	padding-top: 150px;
	.cart-empty-image{
		width: 90px;
		height: 90px;
	}
	.tip-text{
		font-size: 12px;
		color: gray;
		margin-top: 15px;
	}
}

</style>
